from django.core.paginator import Paginator
from django.shortcuts import render

# Create your views here.
from app01.models import LanYueChuan


def show(request,page_id):
    # 直接拿值，不用去前端点了,当你只需要某个字段值时，values('name')是返回字典
    # lanyuechuans = LanYueChuan.objects.all().values_list('name',flat=True)
    lanyuechuans = LanYueChuan.objects.all()

    # 要分页就先拿到要分页的内容传进去，每页展示7条
    paginator = Paginator(lanyuechuans, 7)
    print(paginator.num_pages)
    print(paginator.page_range)
    if page_id == '':
        # 再用paginator实力对象的page方法，传入一个页码，返回值values就是第一页的所有数据
        page = paginator.page(1)
        return render(request, 'show.html', {'page':page})
    else:
        page = paginator.page(int(page_id))
        return render(request, 'show.html', {'page': page})